package com.gable.report.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by gable on 2018/5/11.
 */
public class RedisListStoreThread implements Runnable{

    private static final Log logger = LogFactory.getLog(RedisListStoreThread.class);

    private RedisTemplate redisTemplate;

    private String key;

    private List list;

    public RedisListStoreThread(RedisTemplate redisTemplate, String key, List list) {
        this.redisTemplate = redisTemplate;
        this.key = key;
        this.list = list;
    }


    @Override
    public void run() {
        try {
            BoundListOperations listOperations = redisTemplate.boundListOps(key);
            if(!CollectionUtils.isEmpty(list)){
                listOperations.rightPushAll(list.toArray());
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("----------redis服务异常-----------");
        }
    }
}
